home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / perl5 / Net / DBus / Service.pm < prev    next >
Encoding:
Perl POD Document  |  2008-02-20  |  2.9 KB  |  152 lines

  1. # -*- perl -*-
  2. #
  3. # Copyright (C) 2004-2006 Daniel P. Berrange
  4. #
  5. # This program is free software; You can redistribute it and/or modify
  6. # it under the same terms as Perl itself. Either:
  7. #
  8. # a) the GNU General Public License as published by the Free
  9. #   Software Foundation; either version 2, or (at your option) any
  10. #   later version,
  11. #
  12. # or
  13. #
  14. # b) the "Artistic License"
  15. #
  16. # The file "COPYING" distributed along with this file provides full
  17. # details of the terms and conditions of the two licenses.
  18.  
  19. =pod
  20.  
  21. =head1 NAME
  22.  
  23. Net::DBus::Service - Provide a service to the bus for clients to use
  24.  
  25. =head1 SYNOPSIS
  26.  
  27.   package main;
  28.  
  29.   use Net::DBus;
  30.  
  31.   # Attach to the bus
  32.   my $bus = Net::DBus->find;
  33.  
  34.   # Acquire a service 'org.demo.Hello'
  35.   my $service = $bus->export_service("org.demo.Hello");
  36.  
  37.   # Export our object within the service
  38.   my $object = Demo::HelloWorld->new($service);
  39.  
  40.   ....rest of program...
  41.  
  42. =head1 DESCRIPTION
  43.  
  44. This module represents a service which is exported to the message
  45. bus. Once a service has been exported, it is possible to create
  46. and export objects to the bus.
  47.  
  48. =head1 METHODS
  49.  
  50. =over 4
  51.  
  52. =cut
  53.  
  54.  
  55. package Net::DBus::Service;
  56.  
  57. use 5.006;
  58. use strict;
  59. use warnings;
  60.  
  61. =item my $service = Net::DBus::Service->new($bus, $name);
  62.  
  63. Create a new service, attaching to the bus provided in
  64. the C<$bus> parameter, which should be an instance of
  65. the L<Net::DBus> object. The C<$name> parameter is the
  66. qualified service name. It is not usually neccessary to
  67. use this constructor, since services can be created via
  68. the C<export_service> method on the L<Net::DBus> object.
  69.  
  70. =cut
  71.  
  72. sub new {
  73.     my $class = shift;
  74.     my $self = {};
  75.  
  76.     $self->{bus} = shift;
  77.     $self->{service_name} = shift;
  78.     $self->{objects} = {};
  79.     
  80.     bless $self, $class;
  81.  
  82.     $self->get_bus->get_connection->request_name($self->get_service_name);
  83.  
  84.     return $self;
  85. }
  86.  
  87. =item my $bus = $service->get_bus;
  88.  
  89. Retrieves the L<Net::DBus> object to which this service is
  90. attached.
  91.  
  92. =cut
  93.  
  94. sub get_bus {
  95.     my $self = shift;
  96.     return $self->{bus};
  97. }
  98.  
  99. =item my $name = $service->get_service_name
  100.  
  101. Retrieves the qualified name by which this service is 
  102. known on the bus.
  103.  
  104. =cut
  105.  
  106. sub get_service_name {
  107.     my $self = shift;
  108.     return $self->{service_name};
  109. }
  110.  
  111.  
  112. sub _register_object {
  113.     my $self = shift;
  114.     my $object = shift;
  115.     #my $wildcard = shift || 0;
  116.     
  117. #    if ($wildcard) {
  118. #    $self->get_bus->get_connection->
  119. #        register_fallback($object->get_object_path,
  120. #                  sub {
  121. #                  $object->_dispatch(@_);
  122. #                  });
  123. #    } else {
  124.     $self->get_bus->get_connection->
  125.         register_object_path($object->get_object_path,
  126.                  sub {
  127.                      $object->_dispatch(@_);
  128.                  });
  129. #    }
  130. }
  131.  
  132.  
  133. sub _unregister_object {
  134.     my $self = shift;
  135.     my $object = shift;
  136.  
  137.     $self->get_bus->get_connection->
  138.     unregister_object_path($object->get_object_path);
  139. }
  140.  
  141. 1;
  142.  
  143. =pod
  144.  
  145. =back
  146.  
  147. =head1 SEE ALSO
  148.  
  149. L<Net::DBus>, L<Net::DBus::Object>, L<Net::DBus::RemoteService>
  150.  
  151. =cut
  152.